package com.maycari.captainbi.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.maycari.captainbi.common.constant.CaptainBIConstant;
import com.maycari.captainbi.data.dto.Captain15Dto;
import com.maycari.captainbi.data.dto.Captain3Dto;
import com.maycari.captainbi.data.dto.Captain47Dto;
import com.maycari.captainbi.data.dto.Captain49Dto;
import com.maycari.captainbi.data.po.Captain12Po;
import com.maycari.captainbi.data.po.Captain15Po;
import com.maycari.captainbi.data.po.Captain47Po;
import com.maycari.captainbi.data.po.Captain49Po;
import com.maycari.captainbi.listener.SyncDto;
import com.maycari.captainbi.listener.SyncListener;
import com.maycari.captainbi.mapper.Captain49Dao;
import com.maycari.captainbi.service.Captain49Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maycari.captainbi.util.CaptainBIUtil;
import com.maycari.tool.utils.BeanUtil;
import com.maycari.tool.utils.CollectionUtil;
import com.maycari.tool.utils.DateUtil;
import com.maycari.tool.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 郝伟
 * @since 2021-04-02
 */
@Service
@Slf4j
public class Captain49ServiceImpl extends ServiceImpl<Captain49Dao, Captain49Po> implements Captain49Service {
    @Autowired
    private JmsTemplate jmsTemplate;

    @Override
    public List<Captain47Dto> queryListAll() {
        Date start_time = DateUtil.parse("2021-04-01 00:00:00", DateUtil.PATTERN_DATETIME);
        String result = new String();
        try {
            Date end_time = DateUtil.plusMonths(start_time, 1);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            int page = 1;
            int page_size = 20;
/*
            String buhuo = "3";
*/
            TreeMap<String, String> params = new TreeMap<>();
/*
            params.put("buhuo",buhuo);
*/
            params.put("page", String.valueOf(page));
            params.put("page_size", String.valueOf(page_size));
            params.put("start_time", simpleDateFormat.format(start_time));
            params.put("end_time", simpleDateFormat.format(end_time));
            String action = "http://cronapi.captainbi.com/index.php?m=cronapi&c=fba&a=getAmazonFbaInventoryV3List";

            result = CaptainBIUtil.sendRequest(action, params);

            JSONObject jsonObject = JSON.parseObject(result);
            String data = jsonObject.getString("data");
            System.out.println(data);
            if (StringUtil.isNotBlank(data)) {
                JSONArray objects = JSON.parseArray(data);
                for (int i = 0; i < objects.size(); i++) {
                    JSONObject jsonObject1 = objects.getJSONObject(i);
                    String yjzhz = jsonObject1.getString("yjzhz");
                    String available_days = jsonObject1.getString("available_days");
                    String reserved_customerorders = jsonObject1.getString("reserved_customerorders");
                    String inbound_receiving_quantity = jsonObject1.getString("inbound_receiving_quantity");
                    String glhz = jsonObject1.getString("glhz");
                    String ccf = jsonObject1.getString("ccf");
                    String ccf_every = jsonObject1.getString("ccf_every");
                    String ltsf_12 = jsonObject1.getString("ltsf_12");
                    String month_age12 = jsonObject1.getString("_12_month_age");
                    String day_sale = jsonObject1.getString("day_sale");
                    String ltsf_6_12 = jsonObject1.getString("ltsf_6_12");
                    String total_quantity = jsonObject1.getString("total_quantity");
                    String id = jsonObject1.getString("id");
                    String ltsf_6_12_uk = jsonObject1.getString("ltsf_6_12_uk");
                    String fulfillable_quantity = jsonObject1.getString("fulfillable_quantity");
                    String create_time = jsonObject1.getString("create_time");
                    String month_age69 = jsonObject1.getString("_6_9_month_age");
                    String volume = jsonObject1.getString("volume");
                    String unsellable_quantity = jsonObject1.getString("unsellable_quantity");
                    String month_age36 = jsonObject1.getString("_3_6_month_age");
                    String mfn_listing_exist = jsonObject1.getString("mfn_listing_exist");
                    String parent_asin = jsonObject1.getString("parent_asin");
                    String seller_sku = jsonObject1.getString("seller_sku");
                    String suggested_replenishment_time = jsonObject1.getString("suggested_replenishment_time");
                    String month_age3 = jsonObject1.getString("_3_month_age");
                    String replenishment_quantity = jsonObject1.getString("replenishment_quantity");
                    String doi = jsonObject1.getString("doi");
                    String inbound_working_quantity = jsonObject1.getString("inbound_working_quantity");
                    String mfn_fulfillable_quantity = jsonObject1.getString("mfn_fulfillable_quantity");
                    String ccf_every_uk = jsonObject1.getString("ccf_every_uk");
                    String reserved_time = jsonObject1.getString("reserved_time");
                    String ltsf_6_12_num = jsonObject1.getString("ltsf_6_12_num");
                    String modified_time = jsonObject1.getString("modified_time");
                    String ltsf_12_uk = jsonObject1.getString("ltsf_12_uk");
                    String glccf_uk = jsonObject1.getString("glccf_uk");
                    String health_time = jsonObject1.getString("health_time");
                    String reserved_qty = jsonObject1.getString("reserved_qty");
                    String glccf = jsonObject1.getString("glccf");
                    String month_age912 = jsonObject1.getString("_9_12_month_age");
                    String reserved_fc_transfers = jsonObject1.getString("reserved_fc_transfers");
                    String yjzhz_zb = jsonObject1.getString("yjzhz_zb");
                    String ltsf = jsonObject1.getString("ltsf");
                    String reserved_fc_processing = jsonObject1.getString("reserved_fc_processing");
                    String ltsf_uk = jsonObject1.getString("ltsf_uk");
                    String inbound_shipped_quantity = jsonObject1.getString("inbound_shipped_quantity");
                    String amazon_goods_id = jsonObject1.getString("amazon_goods_id");
                    String fba_time = jsonObject1.getString("fba_time");
                    String asin = jsonObject1.getString("asin");
                    String ltsf_num = jsonObject1.getString("ltsf_num");
                    String ccf_uk = jsonObject1.getString("ccf_uk");
                    String available_stock = jsonObject1.getString("available_stock");
                    String ltsf_12_num = jsonObject1.getString("ltsf_12_num");

                    Captain49Po captain49Po = new Captain49Po();
                    captain49Po.setAmazonGoodsId(jsonObject1.getLong("amazon_goods_id"));
                    captain49Po.setAsin(asin);
                    captain49Po.setAvailableDays(Integer.valueOf(available_days));
                    captain49Po.setCcf(new BigDecimal(ccf));
                    captain49Po.setAvailableStock(Integer.valueOf(available_stock));
                    captain49Po.setCcfEvery(new BigDecimal(ccf_every));
                    captain49Po.setCcfEveryUk(new BigDecimal(ccf_every_uk));
                    captain49Po.setCcfUk(new BigDecimal(ccf_uk));
                    captain49Po.setCreateTime(Integer.valueOf(create_time));
                    captain49Po.setDaySale(new BigDecimal(day_sale));
                    captain49Po.setDoi(doi);
                    captain49Po.setFbaTime(Integer.valueOf(fba_time));
                    captain49Po.setFulfillableQuantity(Integer.valueOf(fulfillable_quantity));
                    captain49Po.setGlccf(new BigDecimal(glccf));
                    captain49Po.setGlccfUk(new BigDecimal(glccf_uk));
                    captain49Po.setGlhz(new BigDecimal(glhz));
                    captain49Po.setHealthTime(Integer.valueOf(health_time));
                    captain49Po.setId(jsonObject1.getLong("id"));
                    captain49Po.setInboundReceivingQuantity(Integer.valueOf(inbound_receiving_quantity));
                    captain49Po.setInboundShippedQuantity(Integer.valueOf(inbound_shipped_quantity));
                    captain49Po.setInboundWorkingQuantity(Integer.valueOf(inbound_working_quantity));
                    captain49Po.setLtsf(new BigDecimal(ltsf));
                    captain49Po.setLtsf12(new BigDecimal(ltsf_12));
                    captain49Po.setLtsf12Num(Integer.valueOf(ltsf_12_num));
                    captain49Po.setLtsf12Uk(new BigDecimal(ltsf_12_uk));
                    captain49Po.setLtsf612(jsonObject1.getBigDecimal("ltsf_6_12"));
                    captain49Po.setLtsf612Num(jsonObject1.getInteger("ltsf_6_12_num"));
                    captain49Po.setLtsf612Uk(jsonObject1.getBigDecimal("ltsf_6_12_uk"));
                    captain49Po.setLtsfNum(Integer.valueOf(ltsf_num));
                    captain49Po.setLtsfUk(new BigDecimal(ltsf_uk));
                    captain49Po.setMfnFulfillableQuantity(Integer.valueOf(mfn_fulfillable_quantity));
                    captain49Po.setMfnListingExist(Integer.valueOf(mfn_listing_exist));
                    captain49Po.setModifiedTime(Integer.valueOf(modified_time));
                    captain49Po.setMonthAge3(Integer.valueOf(month_age3));
                    captain49Po.setMonthAge12(Integer.valueOf(month_age12));
                    captain49Po.setMonthAge36(Integer.valueOf(month_age36));
                    captain49Po.setMonthAge69(Integer.valueOf(month_age69));
                    captain49Po.setMonthAge912(Integer.valueOf(month_age912));
                    captain49Po.setParentAsin(parent_asin);
                    captain49Po.setReplenishmentQuantity(new BigDecimal(replenishment_quantity));
                    captain49Po.setReservedCustomerorders(Integer.valueOf(reserved_customerorders));
                    captain49Po.setReservedFcProcessing(Integer.valueOf(reserved_fc_processing));
                    captain49Po.setReservedFcTransfers(Integer.valueOf(reserved_fc_transfers));
                    captain49Po.setReservedQty(Integer.valueOf(reserved_qty));
                    captain49Po.setReservedTime(Integer.valueOf(reserved_time));
                    captain49Po.setSellerSku(seller_sku);
                    captain49Po.setSuggestedReplenishmentTime(Integer.valueOf(suggested_replenishment_time));
                    captain49Po.setTotalQuantity(Integer.valueOf(total_quantity));
                    captain49Po.setUnsellableQuantity(Integer.valueOf(unsellable_quantity));
                    captain49Po.setVolume(new BigDecimal(volume));
                    captain49Po.setYjzhz(new BigDecimal(yjzhz));
                    captain49Po.setYjzhzZb(new BigDecimal(yjzhz_zb));

                    baseMapper.save(captain49Po);


                }
                /*List<Captain49Po> captain47Pos = JSON.parseArray(data, Captain49Po.class);
                for (int i = 0; i < captain47Pos.size(); i++) {
                    Captain49Po captain47Po = captain47Pos.get(i);
                        *//*String channel_name = captain47Po.getChannelName();
                        String thumb_path = captain47Po.getThumbPath();
                        String available_days = captain47Po.getAvailableDays();
                        String inbound_working_quantity = captain47Po.getInboundWorkingQuantity();
                        String fulfillable_quantity = captain47Po.getFulfillableQuantity();
                        String inbound_receiving_quantity = captain47Po.getInboundReceivingQuantity();
                        String titleS = captain47Po.getTitles();
                        String unsellable_quantity = captain47Po.getUnsellableQuantity();
                        String inbound_shipped_quantity = captain47Po.getInboundShippedQuantity();
                        String modified_time = captain47Po.getModifiedTime();
                        Integer mfn_listing_exist = captain47Po.getMfnListingExist();
                        Integer buhuo = captain47Po.getBuhuo();
                        String reserved_quantity = captain47Po.getReservedQuantity();
                        String asinS = captain47Po.getAsins();
                        String seller_sku = captain47Po.getSellerSku();
                        String suggested_replenishment_time = captain47Po.getSuggestedReplenishmentTime();
                        String available_stock = captain47Po.getAvailableStock();
                        Integer replenishment_quantity = captain47Po.getReplenishmentQuantity();*//**//*

                        map.put("titles", captain47Po.getTitles());
                        map.put("thumbPath", captain47Po.getThumbPath());
                        map.put("asins", captain47Po.getAsins());
                        map.put("sellerSku", captain47Po.getSellerSku());
                        map.put("mfnListingExist", captain47Po.getMfnListingExist());
                        map.put("channelName", captain47Po.getChannelName());
                        map.put("buhuo", captain47Po.getBuhuo());
                        map.put("availableDays", captain47Po.getAvailableDays());
                        map.put("replenishmentQuantity", captain47Po.getReplenishmentQuantity());
                        map.put("suggestedReplenishmentTime", captain47Po.getSuggestedReplenishmentTime());
                        map.put("fulfillableQuantity", captain47Po.getFulfillableQuantity());
                        map.put("inboundShippedQuantity", captain47Po.getInboundShippedQuantity());
                        map.put("inboundReceivingQuantity", captain47Po.getInboundReceivingQuantity());
                        map.put("availableStock", captain47Po.getAvailableStock());
                        map.put("reservedQuantity", captain47Po.getReservedQuantity());
                        map.put("unsellableQuantity", captain47Po.getUnsellableQuantity());
                        map.put("inboundWorkingQuantity", captain47Po.getInboundWorkingQuantity());
                        map.put("modifiedTime", captain47Po.getModifiedTime());*//*
                    captain47Po.setLtsf612(captain47Po.getLtsf612());
                    save(captain47Po);
                }*/
            }



                /*JSONObject jsonObject1 = (JSONObject) jsonObject.get("data");
                if (ObjectUtils.isNotEmpty(jsonObject1)) {
                    for (int i = 0; i < jsonObject1.size(); i++) {
                        String channel_name = jsonObject1.getString("channel_name");
                        String thumb_path = jsonObject1.getString("thumb_path");
                        String available_days = jsonObject1.getString("available_days");
                        String inbound_working_quantity = jsonObject1.getString("inbound_working_quantity");
                        String fulfillable_quantity = jsonObject1.getString("fulfillable_quantity");
                        String inbound_receiving_quantity = jsonObject1.getString("inbound_receiving_quantity");
                        String titleS = jsonObject1.getString("TitleS");
                        String unsellable_quantity = jsonObject1.getString("unsellable_quantity");
                        String inbound_shipped_quantity = jsonObject1.getString("inbound_shipped_quantity");
                        String modified_time = jsonObject1.getString("modified_time");
                        String mfn_listing_exist = jsonObject1.getString("mfn_listing_exist");
                        String buhuo = jsonObject1.getString("buhuo");
                        String reserved_quantity = jsonObject1.getString("reserved_quantity");
                        String asinS = jsonObject1.getString("AsinS");
                        String seller_sku = jsonObject1.getString("seller_sku");
                        String suggested_replenishment_time = jsonObject1.getString("suggested_replenishment_time");
                        String available_stock = jsonObject1.getString("available_stock");
                        String replenishment_quantity = jsonObject1.getString("replenishment_quantity");

                        Map<String, Object> map = new HashMap<>();
                        map.put("titles", titleS);
                        map.put("thumbPath", thumb_path);
                        map.put("asins", asinS);
                        map.put("sellerSku", seller_sku);
                        map.put("mfnListingExist", mfn_listing_exist);
                        map.put("channelName", channel_name);
                        map.put("buhuo", buhuo);
                        map.put("availableDays", available_days);
                        map.put("replenishmentQuantity", replenishment_quantity);
                        map.put("suggestedReplenishmentTime", suggested_replenishment_time);
                        map.put("fulfillableQuantity", fulfillable_quantity);
                        map.put("inboundShippedQuantity", inbound_shipped_quantity);
                        map.put("inboundReceivingQuantity", inbound_receiving_quantity);
                        map.put("availableStock", available_stock);
                        map.put("reservedQuantity", reserved_quantity);
                        map.put("unsellableQuantity", unsellable_quantity);
                        map.put("inboundWorkingQuantity", inbound_working_quantity);
                        map.put("modifiedTime", modified_time);

                        System.out.println(map);
                    }
                }
*/
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean sync(Integer authorizationId, Date startTime, Date endTime) {

        SyncDto dto = new SyncDto();
        dto.setAuthorizationId(authorizationId);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        dto.setBeanId("captain49ServiceImpl");
        TreeMap<String, String> params = new TreeMap<>();
        params.put("start_time", simpleDateFormat.format(startTime));
        params.put("end_time", simpleDateFormat.format(endTime));
        dto.setUrl(CaptainBIConstant.CaptainBIUrl.url_49.value());
        dto.setParams(params);
        jmsTemplate.convertAndSend(SyncListener.SYNC_LISTENER, dto);
        return true;
    }

    private List<Captain49Po> coverData(JSONArray jsonArray) {
        List<Captain49Po> collect = jsonArray.stream().map(arr -> {
            JSONObject jsonObject1 = (JSONObject) arr;
            String yjzhz = jsonObject1.getString("yjzhz");
            String available_days = jsonObject1.getString("available_days");
            String reserved_customerorders = jsonObject1.getString("reserved_customerorders");
            String inbound_receiving_quantity = jsonObject1.getString("inbound_receiving_quantity");
            String glhz = jsonObject1.getString("glhz");
            String ccf = jsonObject1.getString("ccf");
            String ccf_every = jsonObject1.getString("ccf_every");
            String ltsf_12 = jsonObject1.getString("ltsf_12");
            String month_age12 = jsonObject1.getString("_12_month_age");
            String day_sale = jsonObject1.getString("day_sale");
            String ltsf_6_12 = jsonObject1.getString("ltsf_6_12");
            String total_quantity = jsonObject1.getString("total_quantity");
            String id = jsonObject1.getString("id");
            String ltsf_6_12_uk = jsonObject1.getString("ltsf_6_12_uk");
            String fulfillable_quantity = jsonObject1.getString("fulfillable_quantity");
            String create_time = jsonObject1.getString("create_time");
            String month_age69 = jsonObject1.getString("_6_9_month_age");
            String volume = jsonObject1.getString("volume");
            String unsellable_quantity = jsonObject1.getString("unsellable_quantity");
            String month_age36 = jsonObject1.getString("_3_6_month_age");
            String mfn_listing_exist = jsonObject1.getString("mfn_listing_exist");
            String parent_asin = jsonObject1.getString("parent_asin");
            String seller_sku = jsonObject1.getString("seller_sku");
            String suggested_replenishment_time = jsonObject1.getString("suggested_replenishment_time");
            String month_age3 = jsonObject1.getString("_3_month_age");
            String replenishment_quantity = jsonObject1.getString("replenishment_quantity");
            String doi = jsonObject1.getString("doi");
            String inbound_working_quantity = jsonObject1.getString("inbound_working_quantity");
            String mfn_fulfillable_quantity = jsonObject1.getString("mfn_fulfillable_quantity");
            String ccf_every_uk = jsonObject1.getString("ccf_every_uk");
            String reserved_time = jsonObject1.getString("reserved_time");
            String ltsf_6_12_num = jsonObject1.getString("ltsf_6_12_num");
            String modified_time = jsonObject1.getString("modified_time");
            String ltsf_12_uk = jsonObject1.getString("ltsf_12_uk");
            String glccf_uk = jsonObject1.getString("glccf_uk");
            String health_time = jsonObject1.getString("health_time");
            String reserved_qty = jsonObject1.getString("reserved_qty");
            String glccf = jsonObject1.getString("glccf");
            String month_age912 = jsonObject1.getString("_9_12_month_age");
            String reserved_fc_transfers = jsonObject1.getString("reserved_fc_transfers");
            String yjzhz_zb = jsonObject1.getString("yjzhz_zb");
            String ltsf = jsonObject1.getString("ltsf");
            String reserved_fc_processing = jsonObject1.getString("reserved_fc_processing");
            String ltsf_uk = jsonObject1.getString("ltsf_uk");
            String inbound_shipped_quantity = jsonObject1.getString("inbound_shipped_quantity");
            String amazon_goods_id = jsonObject1.getString("amazon_goods_id");
            String fba_time = jsonObject1.getString("fba_time");
            String asin = jsonObject1.getString("asin");
            String ltsf_num = jsonObject1.getString("ltsf_num");
            String ccf_uk = jsonObject1.getString("ccf_uk");
            String available_stock = jsonObject1.getString("available_stock");
            String ltsf_12_num = jsonObject1.getString("ltsf_12_num");

            Captain49Po captain49Po = new Captain49Po();
            captain49Po.setAmazonGoodsId(jsonObject1.getLong("amazon_goods_id"));
            captain49Po.setAsin(asin);
            captain49Po.setAvailableDays(Integer.valueOf(available_days));
            captain49Po.setCcf(new BigDecimal(ccf));
            captain49Po.setAvailableStock(Integer.valueOf(available_stock));
            captain49Po.setCcfEvery(new BigDecimal(ccf_every));
            captain49Po.setCcfEveryUk(new BigDecimal(ccf_every_uk));
            captain49Po.setCcfUk(new BigDecimal(ccf_uk));
            captain49Po.setCreateTime(Integer.valueOf(create_time));
            captain49Po.setDaySale(new BigDecimal(day_sale));
            captain49Po.setDoi(doi);
            captain49Po.setFbaTime(Integer.valueOf(fba_time));
            captain49Po.setFulfillableQuantity(Integer.valueOf(fulfillable_quantity));
            captain49Po.setGlccf(new BigDecimal(glccf));
            captain49Po.setGlccfUk(new BigDecimal(glccf_uk));
            captain49Po.setGlhz(new BigDecimal(glhz));
            captain49Po.setHealthTime(Integer.valueOf(health_time));
            captain49Po.setId(jsonObject1.getLong("id"));
            captain49Po.setInboundReceivingQuantity(Integer.valueOf(inbound_receiving_quantity));
            captain49Po.setInboundShippedQuantity(Integer.valueOf(inbound_shipped_quantity));
            captain49Po.setInboundWorkingQuantity(Integer.valueOf(inbound_working_quantity));
            captain49Po.setLtsf(new BigDecimal(ltsf));
            captain49Po.setLtsf12(new BigDecimal(ltsf_12));
            captain49Po.setLtsf12Num(Integer.valueOf(ltsf_12_num));
            captain49Po.setLtsf12Uk(new BigDecimal(ltsf_12_uk));
            captain49Po.setLtsf612(jsonObject1.getBigDecimal("ltsf_6_12"));
            captain49Po.setLtsf612Num(jsonObject1.getInteger("ltsf_6_12_num"));
            captain49Po.setLtsf612Uk(jsonObject1.getBigDecimal("ltsf_6_12_uk"));
            captain49Po.setLtsfNum(Integer.valueOf(ltsf_num));
            captain49Po.setLtsfUk(new BigDecimal(ltsf_uk));
            captain49Po.setMfnFulfillableQuantity(Integer.valueOf(mfn_fulfillable_quantity));
            captain49Po.setMfnListingExist(Integer.valueOf(mfn_listing_exist));
            captain49Po.setModifiedTime(Integer.valueOf(modified_time));
            captain49Po.setMonthAge3(Integer.valueOf(month_age3));
            captain49Po.setMonthAge12(Integer.valueOf(month_age12));
            captain49Po.setMonthAge36(Integer.valueOf(month_age36));
            captain49Po.setMonthAge69(Integer.valueOf(month_age69));
            captain49Po.setMonthAge912(Integer.valueOf(month_age912));
            captain49Po.setParentAsin(parent_asin);
            captain49Po.setReplenishmentQuantity(new BigDecimal(replenishment_quantity));
            captain49Po.setReservedCustomerorders(Integer.valueOf(reserved_customerorders));
            captain49Po.setReservedFcProcessing(Integer.valueOf(reserved_fc_processing));
            captain49Po.setReservedFcTransfers(Integer.valueOf(reserved_fc_transfers));
            captain49Po.setReservedQty(Integer.valueOf(reserved_qty));
            captain49Po.setReservedTime(Integer.valueOf(reserved_time));
            captain49Po.setSellerSku(seller_sku);
            captain49Po.setSuggestedReplenishmentTime(Integer.valueOf(suggested_replenishment_time));
            captain49Po.setTotalQuantity(Integer.valueOf(total_quantity));
            captain49Po.setUnsellableQuantity(Integer.valueOf(unsellable_quantity));
            captain49Po.setVolume(new BigDecimal(volume));
            captain49Po.setYjzhz(new BigDecimal(yjzhz));
            captain49Po.setYjzhzZb(new BigDecimal(yjzhz_zb));
            captain49Po.setAuthorizationId(Integer.valueOf(jsonObject1.getString("authorizationId")));
//            Captain49Dto po = BeanUtil.copy(captain49Po, Captain49Dto.class);
            return captain49Po;
        }).collect(Collectors.toList());
        return collect;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertBatch(JSONArray jsonArray) {
        log.info("##########################################---49----批量保存------");
        List<Captain49Po> captains = coverData(jsonArray);

        List<Captain49Po> addList = new ArrayList<>();
        List<Captain49Po> updateList = new ArrayList<>();
//        List<Captain49Po> captains = jsonArray.toJavaList(Captain49Po.class);

        for (Captain49Po captain : captains) {
            LambdaQueryWrapper<Captain49Po> la = new LambdaQueryWrapper<>();
            la.eq(Captain49Po::getId, captain.getId());
            if (count(la) == 0) {
                addList.add(captain);
            } else {
                updateList.add(captain);
            }
        }

        if (CollectionUtil.isNotEmpty(addList)) {
            saveBatch(addList);
        }

        if (CollectionUtil.isNotEmpty(updateList)) {
            updateBatchById(updateList);
        }
        return true;

    }
}
